<template>
  <div class="c-fff contact fz-14" @click="contact">
    <van-icon name="service-o" class="mr-5 fz-20"/>
    客服
  </div>
</template>

<script>
import { getLocations } from '@/projects/invoice/utils/storage'
import { listOrderInvoice } from "@/projects/invoice/api/home/index";
import { Toast } from 'vant'
import { open as openContact, setConfig } from '@/projects/invoice/utils/qiyukf';

const contact = (options) => {
  openContact(options);
  // window.location.href = 'https://hzsxmbzhbyxgs3.qiyukf.com/client?k=7d1d2db2bef979175a273a8a1b4b1a9b&wp=1&robotShuntSwitch=0&shuntId=1104609&language=zh-cn'
}

export default {
  data() {
    return {

    };
  },
  methods: {
    contact() {
      const orderHistoryPhone = getLocations('orderHistoryPhone');
      const phoneTokenMap = getLocations('phoneTokenMap') || {};
      if (orderHistoryPhone && phoneTokenMap[orderHistoryPhone]) {
        listOrderInvoice({
          phone: orderHistoryPhone,
          phoneToken: phoneTokenMap[orderHistoryPhone],
        }).then(res => {
          console.log(res)
          const list = (res.data || [])
          const fisrt = list.length ? list[list.length - 1] : undefined
          if (fisrt) {
            setConfig({
              mobile: orderHistoryPhone,
              data: JSON.stringify([
                {"key": "xmbzNo", "value": fisrt.xmbzNo, "type": "crm_param", "area": "order"},
                {"key": "phone", "value": orderHistoryPhone, "type": "crm_param", "area": "order"},
              ]),
              success: function(){
                // todo
                contact();
              },
            })
          } else {
            contact();
          }
        })
      } else {
        Toast.fail("请先验证手机号！");
        this.$router.push({
          path: '/invoice-list',
          query: {
            page: 'login'
          }
        })
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.contact {
  display: flex;
  align-items: center;
}
</style>